Attribute VB_Name = "SafeArrayData"
'***************************************************************
' (c) Copyright 2000 Matthew J. Curland
'
' This file is from the CD-ROM accompanying the book:
' Advanced Visual Basic 6: Power Techniques for Everyday Programs
'   Author: Matthew Curland
'   Published by: Addison-Wesley, July 2000
'   ISBN: 0-201-70712-8
'   http://www.PowerVB.com
'
' You are entitled to license free distribution of any application
'   that uses this file if you own a copy of the book, or if you
'   have obtained the file from a source approved by the author. You
'   may redistribute this file only with express written permission
'   of the author.
'
' This file depends on:
'   References:
'     VBoostTypes6.olb (VBoost Object Types (6.0))
'     VBoost6.Dll (VBoost Object Implementation (6.0)) (optional)
'   Files:
'     VBoost.Bas (optional)
'   Minimal VBoost conditionals:
'     VBOOST_INTERNAL = 1 : VBOOST_CUSTOM = 1
'   Conditional Compilation Values:
'     NOVBOOST = 1 'Removes VBoost dependency
'
' This file is discussed in Chapter 2.
'***************************************************************
Option Explicit

Function ArrayDescriptor(ByVal ppSA As Long) As SafeArray
Dim pSA As Long
    'psa = *ppSA
    #If NOVBOOST Then
        CopyMemory pSA, ByVal ppSA, 4
    #Else
        pSA = VBoost.Deref(ppSA)
    #End If
    'Grab the SafeArray descriptor
    CopyMemory ArrayDescriptor, ByVal pSA, LenB(ArrayDescriptor)
End Function

Function ArrayBounds(ByVal ppSA As Long, Bounds() As SafeArrayBound) As Integer
Dim pSA As Long
Dim cDims As Integer
    'psa = *ppSA
    #If NOVBOOST Then
        CopyMemory pSA, ByVal ppSA, 4
    #Else
        pSA = VBoost.Deref(ppSA)
    #End If
    'cDims first item in SAFEARRAY structure
    CopyMemory cDims, ByVal pSA, Len(cDims)
    If cDims Then
        ArrayBounds = cDims
        ReDim Bounds(cDims - 1)
        'Bounds stored immediately after pvData, grab all at once
        'Note use of unsigned add
        #If NOVBOOST Then
            CopyMemory Bounds(0), ByVal (pSA Xor &H80000000) + 16 Xor &H80000000, cDims * LenB(Bounds(0))
        #Else
            CopyMemory Bounds(0), ByVal VBoost.UAdd(pSA, 16), cDims * LenB(Bounds(0))
        #End If
    Else
        Erase Bounds
    End If
End Function

